global projectdir "~"
global datadir "$projectdir/data"

use "$datadir/raw_pulls/w2_lehd_ein_usiris/lehd_ecf_interleave_sein_usiris_ein_2018q4.dta"

keep year quarter mode_naics2007fnl_emp mode_naics2012fnl_emp firmid fas_ein firmage firmsize lbd_match firmid_filled ein

sort ein year quarter

keep if year!=year[_n-1] | ein!=ein[_n-1]

gen flag=1 if year<=2004
keep if year>2004 | (flag==1 & flag!=flag[_n+1])
drop flag

compress
save "$datadir/intermediate_files/lehd_ein_firm_age_size_naics.dta"
